#ifndef __USART_H
#define	__USART_H

#include "stm32f10x.h"
#include <stdio.h>

#define SIMUARTDATAMAX 300
typedef struct
{
	uint16_t RecdataCount;
	uint16_t rcvFlag;
	uint16_t DataNum;
	uint16_t tailPosition;
	uint16_t headPosition;
	uint8_t  RecData[SIMUARTDATAMAX];
} ringBuffer_t;


#define UART2_DE_Pin            GPIO_Pin_8
#define UART2_DE_Port           GPIOA


#define UART5_DE_Pin            GPIO_Pin_8
#define UART5_DE_Port           GPIOB

#define RS4852_Rx(x)   UART5_DE_Port->ODR = (UART5_DE_Port->ODR & ~UART5_DE_Pin)  | (x ? UART5_DE_Pin : 0)
#define RS4852_RxEn()  RS4852_Rx(0)
#define RS4852_RxDen() RS4852_Rx(1)


extern u8 UART1TimeOut;
extern u8 UART2TimeOut;
extern ringBuffer_t Rs485Buf ;
extern uint16_t ChuankouVoly[52] ;
extern uint8_t ChuankouTemp[32] ;
extern uint32_t BalanceBit[4] ;

void Uart1Initial(uint32_t baud);
void Uart2Initial(uint32_t baud);
void Uart4Initial(uint32_t baud);
void Uart5Initial(uint32_t baud);
void Uart1_SendByte(uint8_t *txdBuf,uint16_t len);
void Uart2_SendByte(uint8_t *txdBuf,uint16_t len);
void Uart4_SendByte(uint8_t *txdBuf,uint16_t  len);
void Uart5_SendByte(uint8_t *txdBuf,uint16_t  len);

void dbg_printf( const char* str, ... );
void RingBuf_Write(ringBuffer_t* xUsart,uint8_t data);
uint16_t  user_uart_crc(uint8_t *pchMsg, uint16_t wDataLen);

// #define Dbg_VOLT_FUN 
#ifdef Dbg_CTRL_FUN
#define Dbg_CTRL	dbg_printf
#else
#define Dbg_CTRL(...)
#endif

#ifdef Dbg_VOLT_FUN
#define Dbg_SAMP	dbg_printf
#else
#define Dbg_SAMP(...)
#endif
#ifdef Dbg_SOC_FUN
#define dbg_SOC	dbg_printf
#else
#define dbg_SOC(...)
#endif


#endif /* __USART_H */


